package com.zhiwang.planet.mvvm.viewmodel.main

import androidx.lifecycle.MutableLiveData
import com.uber.autodispose.AutoDispose
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.model.entity.UserDao
import com.zhiwang.planet.mvvm.model.entity.main.IndexActivityBody
import com.zhiwang.planet.mvvm.model.entity.main.IndexData
import com.zhiwang.planet.util.androidSchedule
import com.zhiwang.planet.util.responseFunc
import javax.inject.Inject

class MainRepository @Inject constructor(val restApi: RestApi, val userDao: UserDao) {

    val indexAct = MutableLiveData<IndexActivityBody>()

    val indexData = MutableLiveData<IndexData>()

    val loading = MutableLiveData<Boolean>()

    val err = MutableLiveData<Throwable>()

    fun loadIndexActivity() {

        val dis = restApi.getIndexActivities()
                .androidSchedule()
                .responseFunc()
                .subscribe({
                    indexAct.postValue(it)
                }, {


                }, {

                })
    }

    fun loadIndexData() {
        val disposable = restApi.getIndexData()
                .androidSchedule()
                .responseFunc()
                .subscribe({
                    indexData.value = it
                }, {
                    loading.value = false
                }, {

                })
    }
}